import React, { PureComponent } from 'react'
import "./index.css";

export default class Parent extends PureComponent {

    state ={ car:'奔驰c63'}


    changeCar = () =>{
        this.setState({car:'迈巴赫'})
    }

    // shouldComponentUpdate(nextProps,nextState){
    //     // console.log(this.props,this.state)
    //     // console.log(nextProps,nextState)
    //     if(this.state.car == nextState.car) return false
    //     else return true
    // }

    render() {
        console.log('Parent------render')
        const {car} = this.state
        return (
            <div className='parent'>
                <h3>我是Parent组建</h3>
                <h4>我的车是：{car}</h4>
                <button onClick={this.changeCar}>换车</button>
                <Child car={car}/>
            </div>
        )
    }
}


class Child extends PureComponent {

    // shouldComponentUpdate(nextProps,nextState){
    //     console.log(this.props,this.state)
    //     console.log(nextProps,nextState)
    //     if(this.props.car == nextProps.car) return false
    //     else return true
    // }
    
    render() {
        console.log('Child------render')
        return (
            <div className='child'>
               <h3>我是Child组建</h3>
               <h4>我接收到的车是：{this.props.car}</h4>
            </div>
        )
    }
}